<?php
namespace app\api\controller;
use app\common\controller\Common;
use app\common\exception\ParameterException;
use think\Request;
use think\Loader;


/**
 * @title 广告模块接口
 * @description 接口说明
 * @group 接口分组
 *
 */
class Banner extends Common
{
    /**
     * @title 获取广告位详情
     * @description 接口说明
     * @author WCJ
     * @url /api/banner/get_banner_position
     * @method POST
     * @param name:pid type:int require:0 default:1 other: desc:位置id
     *
     * @return id: 广告位ID
     * @return name: 广告位名称
     * @return desc:顺序
     * @return width:宽
     * @return height:高
     *
     */
    public function get_banner_position(Request $request){
        if($request->isPost()){
            $pid=$request->post('pid');
            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $pid])) {
                throw new ParameterException([ 'msg' => $validate->getError(),'errorCode'=>201]);
                die();
            }
            $bannerlogic=new \app\common\logic\Banner();
            $data=$bannerlogic->getbannerposition($pid);
            return ["code"=>200,"msg"=>"成功","data"=>$data];
        }

    }
  
     /**
     * @title 获取天气详情
     * @description 接口说明
     * @author WCJ
     * @url /api/banner/get_tianqi
     * @method POST
     * @param name:city type:int require:0 default:1 other: desc:城市
     *
     * @return data:数据
     *
     */
    public function get_tianqi(Request $request){
        if($request->isPost()){
           
             $city=$request->post('city');
             $url='http://api.k780.com:88/?app=weather.today&weaid='.$city.'&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json';
            
       
            header("Content-type: text/html; charset=utf-8");
            $ch = curl_init();//初始化curl
            curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
            curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
          
                
            
            $data = curl_exec($ch);//运行curl
           $data=json_decode($data,true);
            curl_close($ch);
          return ["code"=>200,"msg"=>"成功","data"=>$data];
            
        }

    }
  
  

    /**
     * @title 获取广告列表
     * @description 接口说明
     * @author WCJ
     * @url /api/banner/get_bannerlist
     * @method POST
     * @param name:pid type:int require:0 default:1 other: desc:位置id
     *
     * @return id: 广告ID
     * @return name: 广告名称
     * @return imgUrl:图片地址
     * @return imgHref:图片的链接
     * @return addtime:添加时间
     *
     */
    public function get_bannerlist(Request $request){
        if($request->isPost()){
            $pid=$request->post('pid');

            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $pid])) {
                throw new ParameterException(['code' => 201,'errorCode' => 400,  'msg' => $validate->getError()]);
                die();
            }
            $bannerlogic=new \app\common\logic\Banner();
            $data=$bannerlogic->getbannerlist($pid);
            return ["code"=>200,"msg"=>"成功","data"=>$data];
        }

    }


//    /**
//     * @title aa
//     * @description 接口说明
//     * @author WCJ
//     * @url /api/banner/aa
//     * @method POST
//     * @param name:id type:int require:0 default:1 other: desc:id
//     *
//     *
//     */
//    public function aa(Request $request){
//        if($request->isPost()){
//            $id=$request->post('id');
//            $redis = new Redis();
//            $data=session("ccc");
//            return ["code"=>200,"msg"=>"成功","data"=>$data];
//        }
//
//    }
//
//    /**
//     * @title bb
//     * @description 接口说明
//     * @author WCJ
//     * @url /api/banner/bb
//     * @method POST
//     *
//     *
//     */
//    public function bb(Request $request){
//        if($request->isPost()){
//            $data=session("ccc");
//            return ["code"=>200,"msg"=>"成功","data"=>$data];
//        }
//
//    }
}